# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-regexp_property_values
pkgver=1.3.0
_commit=3ecdde76f4721f45ecee885b3701df7ddb70bbe6
pkgrel=2
pkgdesc="Inspect property values supported by Ruby's regex engine"
arch=(loong64 x86_64)
url='https://github.com/jaynetics/regexp_property_values'
license=(MIT)
depends=(ruby)
makedepends=(git)
checkdepends=(ruby-character_set ruby-rake ruby-rake-compiler ruby-range_compressor ruby-rspec)
options=(!emptydirs)
source=(git+https://github.com/jaynetics/regexp_property_values.git#commit=$_commit)
sha256sums=('SKIP')

prepare() {
  cd regexp_property_values
  sed -i -r 's|~>|>=|' Gemfile
  # Don't recompile
  sed -i '/compile/d' Rakefile
  sed -i '/bundler/d' spec/spec_helper.rb
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd regexp_property_values
  gem build regexp_property_values.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    regexp_property_values-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd regexp_property_values
  GEM_HOME="tmp_install/$_gemdir" rspec
}

package() {
  cd regexp_property_values
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
